import configparser
from src.Data.product_db import ProductDB
from src.Core.pet_assistant import VectorSearch

class ProductService:
    def __init__(self):
        config = configparser.ConfigParser()
        config.read('src/config/db_config.ini')
        db_config = {
            'host': config['DATABASE']['host'],
            'port': int(config['DATABASE']['port']),
            'user': config['DATABASE']['user'],
            'password': config['DATABASE']['password'],
            'database': config['DATABASE']['database'],
            'product_table': config['DATABASE']['product_table'],
            'alignment_table': config['DATABASE']['alignment_table']
        }
        self.db = ProductDB(db_config)
        self.search = VectorSearch(index='pet_products')

    def get_product(self, product_id: int) -> dict:
        """获取商品详情"""
        return self.db.get_product(product_id)

    def search_products(self, keyword: str) -> list:
        """搜索商品"""
        return self.db.search_products(keyword)

    def find_similar(self, query: str) -> list:
        """查找相似商品"""
        return self.search.find_similar(query)
